package com.test.controller;

import com.test.domain.Deliveryman;
import com.test.domain.Result;
import com.test.domain.Utils;
import com.test.service.DeliverymanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@CrossOrigin
@RestController
@RequestMapping("/deliveryman")
public class DeliverymanController {

    private final DeliverymanService deliverymanService;

    @Autowired
    public DeliverymanController(DeliverymanService deliverymanService) {
        this.deliverymanService = deliverymanService;
    }

    @PostMapping("/insertDeliveryman")
    public Result insertDeliveryman(@RequestBody Deliveryman deliveryman){
        System.out.println(deliveryman);
        deliverymanService.insertDeliveryman(deliveryman);
        return Utils.success("ok");

    }

    @GetMapping("/deliverymanList")
    public Result getDeliverymanList(@RequestParam("phoneNumber") String phoneNumber){
        System.out.println(phoneNumber);
        return Utils.success(deliverymanService.getDeliverymanList(phoneNumber));
    }


    @GetMapping("/updateDeliverymanIdNumber")
    public Result updateDeliverymanIdNumber(@RequestParam("phoneNumber") String phoneNumber,
                                 @RequestParam("idNumber") String idNumber){
        System.out.println(phoneNumber);
        System.out.println(idNumber);
        deliverymanService.updateIdNumber(phoneNumber,idNumber);
        return Utils.success("ok");
    }

    @GetMapping("/updateSituation")
    public Result updateDishName(@RequestParam("phoneNumber") String phoneNumber,
                                 @RequestParam("situation") int situation){
        System.out.println(phoneNumber);
        System.out.println(situation);
        deliverymanService.updateSituation(phoneNumber,situation);
        return Utils.success("ok");
    }

    @GetMapping("/deleteDeliveryman")
    public Result deleteDeliveryman(@RequestParam("phoneNumber") String phoneNumber){
        deliverymanService.deleteDeliveryman(phoneNumber);
        return Utils.success("ok");
    }

}
